
<?php 
//include($_SERVER['SERVER_NAME'].'/Connect/_connect.php');
include($_SERVER['DOCUMENT_ROOT'].'/mudev/Connect/_connect.php');
function clean(){
	stripslashes();
	mysql_real_escape_string();
	strip_tags();
	}

/*Login
*******************************************************/
$email = "";
$pass = "";
if(isset($_POST["email"]) && isset($_POST["pass"]))
{
	
	$email = strtolower($_POST["email"]);
	$pass = $_POST["pass"];
	//$email = clean($email);
	//$pass = clean($pass);
	$pass = md5($pass);
	//$dataString = array();
	$query = "SELECT * FROM mu_profiles INNER JOIN mu_pass ON mu_profiles.uid = mu_pass.uid_fk
	WHERE mu_profiles.email = '$email' and mu_pass.password = '$pass'";
	//$query2 = "SELECT * FROM mu_profiles WHERE uid = '$email'";
	//$result =  mysqli_query($con,$query);
	if($result =  mysqli_query($con,$query))
		{
		$count = mysqli_num_rows($result);
			if($count == 1){
			$getData = mysqli_query($con,"SELECT * FROM mu_profiles WHERE email = '$email'");
			if($getData){
				if($row = mysqli_fetch_array($getData,MYSQLI_ASSOC)){
					session_start();
					$_SESSION['uid'] = $row['uid'];
					$_SESSION['email'] = $row['email']; 
					$_SESSION['firstname'] = $row['firstname'];
					$_SESSION['lastname'] = $row['lastname'];
					echo "redirect";
					//$dataString = array($_SESSION["firstname"],$_SESSION["lastname"],"home.php");
				}else{ echo "ERROR :: Attempt to get Account data failed!";}
			}else{ echo "ERROR :: Sorry, Failed to get data";}
			//echo implode('++~',$dataString);
			}else{ echo "ERROR :: Invalid Account"; }
		}
	else
		{ echo "ERROR :: Sorry, an error occured";}
	}
/*SignUp
*******************************************************/
if(isset($_POST['f_email'])){
	
	$firstname=$_POST['firstname'];
	$lastname=$_POST['lastname'];
	$email=$_POST['email'];
	$emailr=$_POST['emailr'];
	$password=$_POST['password'];
	$repassword=$_POST['repassword'];
	$gender=$_POST['gender'];
	$birthday_month=$_POST['birthday_month'];
	$birthday_day=$_POST['birthday_day'];
	$birthday_year=$_POST['birthday_year'];
	$tablename="bannau";
	
	$ugtime_now = time() + (60*60*3);
	$date_time = date("Y-m-d H:i:s",$ugtime_now);
	
	$ugtime_now = time() + (60*60*3);
	$date_time = date("Y-m-d H:i:s",$ugtime_now);
	$email = strtolower($_POST['f_email']);
	$query = mysql_query("SELECT * FROM mu_profiles WHERE email = '$email'");
	if($query){
		$count = mysql_num_rows($query);
		if($count != 0){
			$return_array = array($email, "Ooh Sorry <br/> This Account exists");
			echo implode('++~',$return_array);
		}else{
			session_start();
			$_SESSION['email'] = $email;
			//Send email verification email with random guid
			$em_key = md5(uniqid(rand));
			$query = mysql_query("INSERT INTO `muemail_auth`(email,emailkey,createDate) VALUES ('$email','$em_key','$date_time')");
			if($query){
				include('../Mail.php');
				include('../Mail/mime.php');
				$sender = "MunnaU Registration <admin@munnau.com>";
				$to = 'kalandrews1@yahoo.co.jp';
				$subject = 'Email Address Verification';
				$html = '
				<html>
					<body>
						<div style="background-color:#FAFFE5; border:1px solid #ccff00; text-align:center; 
						color:#5a5a5a; border-radius:12px; -moz-border-radius:12px; -webkit-border-radius:12px;">
							<div style="  padding:0; margin:0;">
								<div style="">
									<img src="http://kalandrews.com/images/munnau_hb.png" />
								</div>
								<h1>
									Hello kalandrews1@yahoo.co.jp
								</h1>
								<div>
									<h1>
										Welcome to <a href="http://www.munnau.com" style="text-decoration:none; color:#00F;">munnau.com</a>
									</h1>
								</div>
							</div>
							<h1>
								To complete registration, Click the following link
								<br/> 
								<a href="http://www.kalandrews.com/nsignup.php?em_key='.$em_key.'&email='.$email.'" style="text-decoration:none; color:#00F;">
									www.munnau.com/signup.php?email = '.$email.' & emailkey = '.$em_key.'
								</a>
								<br/>
							</h1>
						</div>
					</body>
				</html>';
				$crlf = "\n";
				$headers = array(
								'From' => $sender,
								'Return-Path' => $sender,
								'Subject'=> $subject);
				$mime = new Mail_mime($crlf);
				$mime -> setHTMLBody($html);
				$body = $mime ->get();
				$headers = $mime -> headers($headers);
				
				$mail =& Mail::factory('mail');
				$mail -> send($to, $headers, $body);
				echo "emailver.php";
			}else{
				echo "error.php";
			}
		}
	}else{
		echo "An error occured";
	}
}


/**** Pear mime mail****/
/*
if(isset($_POST['sendembtn'])){
	
	include('../Mail.php');
	include('../Mail/mime.php');
	
	$sender = "MunnaU Registration <admin@munnau.com>";
	$to = 'kalandrews1@yahoo.co.jp';
	$subject = 'Email Address Verification';
	$html = '
	<html>
		<body>
			<div style="background-color:#FAFFE5; border:1px solid #ccff00; text-align:center; 
			color:#5a5a5a; border-radius:12px; -moz-border-radius:12px; -webkit-border-radius:12px;">
				<div style="  padding:0; margin:0;">
					<div style="">
						<img src="http://kalandrews.com/images/munnau_hb.png" />
					</div>
					<h1>
						Hello kalandrews1@yahoo.co.jp
					</h1>
					<div>
						<h1>
							Welcome to <a href="http://www.munnau.com" style="text-decoration:none; color:#00F;">munnau.com</a>
						</h1>
					</div>
				</div>
				<h1>
					To complete registration, Click the following link
					<br/> 
					<a href="http://www.munnau.com" style="text-decoration:none; color:#00F;">www.munnau.com</a><br/>
				</h1>
			</div>
		</body>
	</html>';
	$crlf = "\n";
	$headers = array(
					'From' => $sender,
					'Return-Path' => $sender,
					'Subject'=> $subject);
	$mime = new Mail_mime($crlf);
	$mime -> setHTMLBody($html);
	$body = $mime ->get();
	$headers = $mime -> headers($headers);
	
	$mail =& Mail::factory('mail');
	$mail -> send($to, $headers, $body);				
}
*/
/*****No pear mime
$msg = "Send greetings";
$message = "we";
if(isset($_POST['sendembtn'])){
	$to = 'kalandrews1@yahoo.co.jp';
	$subject = 'Greetins';
	$message = '
	<html>
		<h2 style="color: blue">Hello Mr Andrew</h2>
		<br/> 
		<div style="border:1px solid #ccff00; text-align:center;">
			<div style=" background-color:#33FF66;">
				<h1>Welcome to <a href="http://www.munnau.com">munnau.com</a></h1>
			</div>
			<div>
				<h1>
					Click 
					<br/> <a href="http://www.munnau.com">www.munnau.com</a><br/>
					To complete registration
				</h1>
			</div>
    	</div>
	</html>';
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	$headers .= 'From: admin@munnau.com' . "\r\n";
	if(mail($to, $subject, $message, $headers)){
		$sendmsg = "Msg sent to" . $to;
	}else{ $sendmsg = "Sending Failed!"; };					
}
*/
/*Test
******************************************************
$fname = "myfirstname";
$lname = "mylastname";
if(isset($_POST["login"])){
	$email = $_POST["username"];
	$query = mysql_query("SELECT * FROM userprofiles WHERE email = '$email'");
	if($query){
		$row = mysql_fetch_array($query);
		if($row){
			$fname = $row["firstname"];
			$lname = $row["lastname"];
			}
		}
	}
	*/
?>